package main.java.com.negromotad.genetics.rules;

import java.util.List;

import org.jgap.IChromosome;
import org.jgap.InvalidConfigurationException;
import org.jgap.NaturalSelector;
import org.jgap.Population;

public class TMCompositeSelector extends NaturalSelector {

	private List<NaturalSelector> selectors;

	public TMCompositeSelector(List<NaturalSelector> theSelectors) {
		this.selectors = theSelectors;
	}

	@Override
	protected void add(IChromosome toAdd) {
	}

	@Override
	public void empty() {
	}

	@Override
	public boolean returnsUniqueChromosomes() {
		return false;
	}

	@Override
	public void select(int manyToSelect, Population a_from_population,
			Population a_to_population) {
		Population temporalPopulation = a_from_population;
		Population temporalDestination = null;
		try {
			for (NaturalSelector selector : selectors) {
				temporalDestination = new Population(a_to_population
						.getConfiguration());
				selector.select(0, temporalPopulation, temporalDestination);
				temporalPopulation = temporalDestination;
			}
			a_to_population
					.setChromosomes(temporalDestination.getChromosomes());
		} catch (InvalidConfigurationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
